﻿Imports Microsoft.VisualStudio.DebuggerVisualizers
Imports System.Collections.Generic
Imports System.Data.Objects
Imports System.Data.Objects.DataClasses
Imports System.IO

<Assembly: DebuggerVisualizer(GetType(EntityVisualizer), GetType(EntityVisualizerObjectSource), _
 Target:=GetType(EntityObject), Description:="Entity visualizer")> 

Public Class EntityVisualizer
    Inherits DialogDebuggerVisualizer


    Protected Overrides Sub Show(ByVal windowService As IDialogVisualizerService, ByVal objectProvider As IVisualizerObjectProvider)

        Dim ds As New DataSet()
        ds.ReadXml(objectProvider.GetData(), XmlReadMode.ReadSchema)

        Using form As New EntityVisualizerForm
            form.dgvData.AutoGenerateColumns = False
            For i As Integer = 0 To form.dgvData.Columns.Count - 1
                form.dgvData.Columns(i).DataPropertyName = ds.Tables(0).Columns(i).ColumnName
            Next
            form.dgvData.DataSource = ds.Tables(0)

            form.lblState.Text = ds.ExtendedProperties("EntityState").ToString
            form.lblType.Text = ds.ExtendedProperties("EntityName").ToString

            form.ShowDialog()
        End Using
    End Sub

End Class
